//
//  OficeTableViewCell.m
//  YunGui
//
//  Created by User on 16/4/19.
//  Copyright © 2016年 hanen. All rights reserved.
//

#import "OficeTableViewCell.h"
#import "Macro.h"
#import "OfficeModel.h"

#define Height(msg) [UIView getHeight:msg]
#define Width(msg) [UIView getWidth:msg]
@interface OficeTableViewCell (){
    CGFloat   space;
    
//    UILabel *_NumberLabel;
//    UILabel *_VisitNameLabel;
//    UILabel *_VisitCountLabel;
}

@end

@implementation OficeTableViewCell

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *officeCell = @"officeCell";
    OficeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:officeCell];
    if (cell == nil) {
        cell = [[OficeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:officeCell];
        //cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell creatCell];
    }   
    
    return cell;
}

- (void)creatCell
{
    space = [UIView getWidth:10.0f];
    
    CGFloat cellH = [OficeTableViewCell cellHeight];
    
    UIImageView  *quan = [[UIImageView alloc] initWithFrame:CGRectMake(space,  space+5, 10.0f, 10.0f)];
    quan.clipsToBounds = YES;
    quan.layer.cornerRadius = 5.0f;
    quan.image = [UIImage imageNamed:@"Btn_Normal_Biaoti"];
    [self.contentView addSubview:quan];
    UILabel *xianLab = [[UILabel alloc] initWithFrame:CGRectMake(quan.x, cellH - 1, kScreenWidth - 2*space, 1)];
    xianLab.backgroundColor = GrayLineColor;
    [self.contentView addSubview:xianLab];
    
    _NumberLabel = [ViewTool getLabelWith:CGRectMake(quan.maxX+5, space, Width(80), 20.0f) WithTitle:@"" WithFontSize:14.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:_NumberLabel];

    _visitNameImg = [[UIImageView alloc] initWithFrame:CGRectMake(_NumberLabel.x, _NumberLabel.maxY+space, 20.0f, 20.0f)];
    _visitNameImg.image = [UIImage imageNamed:@"Btn_Normal_Jingzhengduishou"];
    [self.contentView addSubview:_visitNameImg];
    
    _officelabel = [ViewTool getLabelWith:CGRectMake(_visitNameImg.maxX+5, _visitNameImg.y,  Width(55), 20.0f) WithTitle:@"" WithFontSize:13.0f WithTitleColor:GRAYCOLOR2 WithTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:_officelabel];
    
    _VisitNameLabel = [ViewTool getLabelWith:CGRectMake(_officelabel.maxX, _visitNameImg.y, Width(80), 20.0f) WithTitle:@"" WithFontSize:13.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:_VisitNameLabel];
    
    
    _visitCountImg = [[UIImageView alloc] initWithFrame:CGRectMake(_VisitNameLabel.maxX+10, _VisitNameLabel.y, 20.0f, 20.0f)];
    _visitCountImg.image = [UIImage imageNamed:@"Btn_Normal_baifangcishu"];
    [self.contentView addSubview:_visitCountImg];
    
    UILabel *label = [ViewTool getLabelWith:CGRectMake(_visitCountImg.maxX+5, _visitCountImg.y, Width(55), 20.0f) WithTitle:@"拜访次数:" WithFontSize:13.0f WithTitleColor:GRAYCOLOR2 WithTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:label];
    
    _VisitCountLabel = [ViewTool getLabelWith:CGRectMake(label.maxX, _visitCountImg.y,  Width(60), 20.0f) WithTitle:@"" WithFontSize:13.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [self.contentView addSubview:_VisitCountLabel];
    
}

- (void)setModel:(OfficeModel *)model
{
    _model = model;
    if (model.realname == nil) {
         _VisitNameLabel.text = model.agency_name;
    }
    else{
        _VisitNameLabel.text = model.realname;
    }
    
    _VisitCountLabel.text = [NSString stringWithFormat:@"%@",model.count];
//    NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
//    _VisitCountLabel.text = [numberFormatter stringFromNumber:model.count];

    _NumberLabel.text = model.no;
}

+ (CGFloat)cellHeight
{
    return  [UIView getHeight:65];
}

@end
